# -*- coding: utf-8 -*-
"""
Created on Tue Jul 20 17:24:52 2021

@author: chibi



Humidity54.00Temperature27.40Relay1defaulthumidity60.00defaulttemperature29.00mode1

"""
import requests
import time 

url = "http://192.168.88.215/temp"

while True :
    i = []
    try :
        myurl =  requests.get(url , timeout= 5)
        text =  myurl.text
        #print(text)
        a = text.strip()
        if  (a.find("Humidity") != -1):
            h = a[a.find("Humidity")+len("Humidity"):a.find("Temperature")]
        if  (a.find("Temperature") != -1):
            t = a[a.find("Temperature")+len("Temperature"):a.find("Relay")]
        if  (a.find("Relay")!= -1 ):
            r = a[a.find("Relay")+len("Relay"):a.find("defaulthumidity")]
            if r == "1":
                r = "开"
            else:
                r = "关"
        if  (a.find("defaulthumidity")!= -1 ):
            dh = a[a.find("defaulthumidity")+len("defaulthumidity"):a.find("defaulttemperature")]
        if  (a.find("defaulttemperature")!= -1 ):
            dt = a[a.find("defaulttemperature")+len("defaulttemperature"):a.find("mode")]
        if  (a.find("mode")!= -1 ):
            m = a[a.find("mode")+len("mode"):]
            if m == "1":
                m = "自动"
            else:
                m = "手动"
            
            
        print("当前模式:%s\n当前湿度:%s 当前温度:%s 默认温度:%s 默认温度:%s 继电器开关状态:%s" % (m,h,t,dh,dt,r) )
        
        
    except requests.exceptions.RequestException:
        print("网页超时请求\n")
    
    time.sleep(5)